package net.yambal.android.geo.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelperfatAddress extends SQLiteOpenHelper {
	private static final String DB_NAME = "geo.db";
	private static final int DB_VERSION = 2;
	private static DBHelperfatAddress _my_instance = null;
	
	public DBHelperfatAddress(Context context) {
		super( context.getApplicationContext(), DB_NAME, null, DB_VERSION );
	}
	
	synchronized static
	public DBHelperfatAddress getInstance( Context context ){
		if ( _my_instance == null ){
			_my_instance = new DBHelperfatAddress(context);
		}
		return _my_instance;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		CreateMyLocationTable(db);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if(oldVersion == 1){
			db.execSQL( "ALTER TABLE " + TableFatAddressCatsh.TABLE + " ADD user_label TEXT DEFAULT NULL;" );
		}
	}

	private void CreateMyLocationTable(SQLiteDatabase db){
		db.execSQL("CREATE TABLE IF NOT EXISTS " + TableFatAddressCatsh.TABLE + " (" +
				"_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," +
				"search_key TEXT DEFAULT NULL," +
				"name_space TEXT DEFAULT NULL," +
				"latetude INTEGER NOT NULL," +
				"longitude INTEGER NOT NULL," +
				"adress_line TEXT DEFAULT NULL," +
				"country_code TEXT DEFAULT NULL," +
				"postal_code TEXT DEFAULT NULL," +
				"admin_area TEXT DEFAULT NULL," +
				"locality TEXT DEFAULT NULL," +
				"sub_locality TEXT DEFAULT NULL," +
				"sub_admin_area TEXT DEFAULT NULL," +
				"feature_name TEXT DEFAULT NULL," +
				"thoroughfare TEXT DEFAULT NULL," +
				"sub_thoroughfare TEXT DEFAULT NULL," +
				"premises TEXT DEFAULT NULL," +
				"phone TEXT DEFAULT NULL," +
				"url TEXT DEFAULT NULL," +
				"extend_string_data TEXT DEFAULT NULL," +
				"user_label TEXT DEFAULT NULL" +
				")");
	}

}
